package com.lottery.im.module.result.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.R;
import com.lottery.im.api.result.entity.AllGameInfo;
import com.lottery.im.api.result.entity.AllGameSelectInfo;
import java.util.List;

public class AllGameSelectAdapter extends BaseQuickAdapter<AllGameSelectInfo, BaseViewHolder> {
  private OnGameClickListener mOnGameClickListener;
  private OnCheckAllClickListener mOnCheckAllClickListener;

  public AllGameSelectAdapter(@Nullable List<AllGameSelectInfo> data) {
    super(R.layout.item_game_list, data);
  }

  @Override protected void convert(final BaseViewHolder helper, AllGameSelectInfo item) {
    helper.setText(R.id.tv_game_mode, item.getGameTypeModeName());
    helper.setVisible(R.id.iv_game_mode, "".equals(item.getGameTypeMode()));
    GameSelectGridAdapter mGameGridAdapter =
        new GameSelectGridAdapter(mContext, item.getChildGameTypeList());
    helper.setAdapter(R.id.gv_game, mGameGridAdapter);
    CheckBox mCbCheckAll = helper.getView(R.id.cb_check_all);
    if (item.isCheckAll()) {
      mCbCheckAll.setChecked(true);
      mCbCheckAll.setText(R.string.cancel);
    } else {
      mCbCheckAll.setChecked(false);
      mCbCheckAll.setText(R.string.check_all);
    }
    mCbCheckAll.setOnClickListener(v -> {
      if (null != mOnCheckAllClickListener) {
        mOnCheckAllClickListener.onCheckAllClick(helper.getLayoutPosition());
      }
    });
    mGameGridAdapter.setOnGameItemClickListener(
        childPosition -> mOnGameClickListener.onGameClick(helper.getLayoutPosition(),
            childPosition));
  }

  public void setOnGameClickListener(
      OnGameClickListener onGameClickListener) {
    mOnGameClickListener = onGameClickListener;
  }

  public interface OnGameClickListener {
    void onGameClick(int position, int childPosition);
  }

  public void setOnCheckAllClickListener(
      OnCheckAllClickListener onCheckAllClickListener) {
    mOnCheckAllClickListener = onCheckAllClickListener;
  }

  public interface OnCheckAllClickListener {
    void onCheckAllClick(int position);
  }
}
